import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Home from '@/views/MyHome.vue';

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'home',
    component: Home
  },
  {
    path: '/works',
    name: 'works',
    component: () => import('@/views/MyWorks.vue')
  },
  {
    path: '/diary',
    name: 'diary',
    component: () => import('@/views/MyDiary.vue')
  },
  {
    path: '/contact',
    name: 'contact',
    component: () => import('@/views/MyContact.vue')
  },
  {
    path: '/worksDetail/:id?',
    name: 'worksDetail',
    component: () => import('@/views/WorksDetail.vue')
  },
  {
    path: '/diaryDetail/:id?',
    name: 'diaryDetail',
    component: () => import('@/views/DiaryDetail.vue')
  }
]

const scrollBehavior = (to: any, from: any, savedPosition: any) => {
  if (savedPosition && to.meta.keepAlive) {
    return savedPosition;
  }
  return { left: 0, top: 0 };
}

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
  scrollBehavior
})

export default router
